package com.cn.sku.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.cn.dataSource.Constants;
import com.cn.dataSource.DynamicDataSourceContxtHolder;
import com.cn.sku.SkuGood;
import com.cn.sku.service.SkuGoodService;
import com.cn.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/good")
public class SkuGoodController {

    @Autowired
    private SkuGoodService skuGoodService;

    @Autowired
    DataSource dataSource;


    @RequestMapping("/login")
    public String index(){
        return "main";
    }


    @GetMapping("list")
    public R list(@RequestParam Map<String, Object> params) throws SQLException {
        System.out.println(dataSource.getConnection());
        for (String dataType : Constants.DS_NAME_LIST) {
            DynamicDataSourceContxtHolder.setDataSourceType(dataType);
            PageUtils page = skuGoodService.queryPage(params);
            System.out.println(page);
        }
        return R.ok("成功");
    }

    @GetMapping("list4")
    public String ceshiHello4(@RequestParam Map<String, Object> params) throws SQLException {
        for (String dataType : Constants.DS_NAME_LIST) {
            DynamicDataSourceContxtHolder.setDataSourceType(dataType);
            PageUtils page = skuGoodService.queryPage(params);
            System.out.println(page);
        }
        return "成功";
    }



}
